import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../views/Home/Home.vue'
import Welcome from '../components/Welcome.vue'
import Myorder from '../views/orderManagement/my_order.vue'
import Details from '../views/orderManagement/details.vue'
Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  {
    path: '/home',
    component: Home,
    redirect: '/Welcome',
    children: [
      { path: '/Welcome', component: Welcome },
      { path: '/myorder', component: Myorder },
      // { path: '/details:id', component: Details, props: { details: true } }
      { path: '/details', name: 'movieDetail', component: Details }
    ]
  }

]

const router = new VueRouter({
  routes
})
// 挂在路由
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})

export default router
